package me.thinkjet.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

/**
 * 权限管理控制
 * @ClassName AuthInterceptor
 * @author johnny_zyc
 * @Modified 2013-3-5 下午3:58:25
 * 
 */
public class AuthInterceptor implements Interceptor {

    @Override
    public void intercept(ActionInvocation ai) {
	String key = ai.getActionKey();
	if (key.indexOf("/admin") == 0) {
	    if (ai.getController().getSession().getAttribute("admin") == null) {
		ai.getController().redirect("/admin/login");
		return;
	    }
	}
	if (key.indexOf("/member") == 0) {
	    if (ai.getController().getSession().getAttribute("member") == null) {
		ai.getController().redirect(
			"/login?redirect="
				+ ai.getController().getRequest()
					.getServletPath());
		return;
	    }
	}
	ai.invoke();

    }
}
